﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using PlatWL.Data;
using PlatWL.Models;
using Nancy.ModelBinding;
using PlatWL.Services.Services;
using Nancy.Security;

namespace PlatWL.Modules.Admin
{
    public class UserModule : AdminModule
    {
        public UserModule(UserManage service) : base("user")
        {
            this.RequiresAuthentication();

            Get["/list"] = p =>
              {
                  string key = this.Request.Query["key"];
                  string usertype = this.Request.Query["usertype"];
                  if (!string.IsNullOrEmpty(key))
                  {
                      page.whereParams.Add("key", key);
                  }
                  if (!string.IsNullOrEmpty(usertype))
                  {
                      page.whereParams.Add("usertype", usertype);
                  }
                  service.User_List(ref msg, Client, page);
                  return this.Response.AsJson(msg);
              };
            Get["/model/{id:int}"] = p =>
            {
                service.User_Model(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };
            Post["/add"] = p =>
            {
                var ad = this.Bind<pt_user_account>();
                service.User_Add(ref msg, Client, ad);
                return this.Response.AsJson(msg);
            };
            //禁用/启用
            Get["/enable/{id:int}"] = p =>
            {
                service.User_Enable(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };

        }
    }
}